local sk__fulu = fk.CreateSkill {

  name = "sk__fulu",

  tags = {  },

}



sk__fulu:addEffect(fk.Damaged, {
  name = "sk__fulu",
  anim_type = "masochism",
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for _ = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(sk__fulu.name) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, sk__fulu.name, data) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    room.logic:getEventsByRule(GameEvent.ChangeHp, 3, function (e)
      local damage = e.data.damageEvent
      if damage and damage.from and damage.to == player then
        table.insert(targets, damage.from)
        return true
      end
    end, 1)
    for _, p in ipairs(targets) do
      if not p.dead then
        room:doIndicate(player.id, {p.id})
        if not p:isNude() then
          room:throwCard(table.random(p:getCardIds("he")), sk__fulu.name, p, p)
        end
      end
    end
    targets = {}
    room.logic:getEventsByRule(GameEvent.Recover, 3, function (e)
      local recover = e.data
      if recover.recoverBy and recover.who == player then
        table.insert(targets, recover.recoverBy)
        return true
      end
    end, 1)
    for _, p in ipairs(targets) do
      if not p.dead then
        p:drawCards(1, sk__fulu.name)
      end
    end
  end,
})

return sk__fulu